{extend name="public/base" /}
{block name="css"}
<link href="__INDEX__/css/plugins/iCheck/custom.css" rel="stylesheet">
{/block}
{block name="container"}
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>编码列表</h5>
                        <div style="float: right;">
                         <a  class="btn btn-w-m btn-info" href="{:url('index/stock/fabricCreate')}">添加面料</a> 
                        </div>
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                            <form action="" method="post">
                                <div class="col-sm-3" style="float: right;">
                                    <div class="input-group">
                                        <input type="text" placeholder="请输入面料编号" name="name" class="input-sm form-control"> <span class="input-group-btn">
                                            <button type="submit" class="btn btn-sm btn-primary"> 搜索</button> </span>
                                        </div>
                                    </div>
                                </form>
                                    <div class="col-sm-8">
                                        <div class="input-group" >
                                            <!-- <button class="btn btn-sm btn-primary" onclick="export_data()">导出数据</button> -->
                                        </div>
                                    </div>
                            </div>
                            <div class="table-responsive">
                                <table class="table table-striped">
                                    <thead>  
                                        <tr>
                                          <th></th>
                                            <th>序号</th>
                                            <th>面料图片</th>
                                            <th>面料编号</th>
                                            <th>所属品类</th>
                                            <th>颜色</th>
                                            <th>属性</th>
                                            <th>成分</th>
                                            <th>花色</th>
                                            <th>纱织</th>
                                            <th>价格</th>
                                            <th>类别</th>
                                            <th>总数量</th>
                                            <th>剩余库存</th>
                                            <th>状态</th>
                                            <th>操作</th>

                                        </tr>
                                    </thead>
                                    <tbody>
                                      {volist name="list" id="vo"}
                                     <tr style="height: 70px;">
                                        <td>
                                          <!-- <input type="checkbox" class="i-checks">-->
                                          <input type="checkbox" class="i-checks"  name="input" value="">
                                      </td>
                                      <td>{$vo.id}</td> 
                                      <td style="position: absolute;"><img src="{$vo.picurl}" alt="" style="width: 50px" class="imgBig"></td>
                                      <td>{$vo.ml_num}</td>
                                      <td>{$vo.category}</td>
                                      <td>{$vo.color}</td>
                                      <td>{$vo.shuxing}</td>
                                      <td>{$vo.chengfen}</td>
                                      <td>{$vo.huase}</td>
                                      <td>{$vo.shazhi}</td>
                                      <td>{$vo.price}</td>
                                      <td>{if condition="$vo['leibie'] eq 1"} 国产面料 {else/} 进口面料{/if}</td>
                                      <td>{$vo.all_num}m</td>
                                      <td>{$vo.kucun}m</td>
                                      <td>
                                        {if condition="$vo['status'] eq 1"}
                                         <a href="javascript:;" onclick="updateStatus({$vo.id},0)"><span class="badge badge-success" title="已使用">已使用</span></a>
                                         {else /}
                                         <a href="javascript:;"  onclick="updateStatus({$vo.id},1)" title="已停用"><span class="badge badge-danger">已停用</span></a>
                                         {/if}
                                     </td>
                                     <td> 
                                      <a data-toggle="modal" title="添加库存" href="#modal-form_yundan" onclick="getInfo({$vo.id})"><i class="iconfont icon-tianjiaadd142"></i></a>&emsp;
                                        <a href="{:url('index/stock/fabricUpdate',array('id'=>$vo['id']))}" title="编辑">  
                                          <i class="fa fa-pencil"></i></a>
                                        &emsp;
                                        <a href="javascript:;" onclick="delcode({$vo.id})" title="删除"><i class="iconfont icon-shanchu"></i></a></td>
                                    </tr>
                                    {/volist}
                                </tbody>
                            </table>
                            <div style="float: right;">
                              {$page}
                           </div>
                       </div>

                   </div>
               </div>
           </div>

       </div>
   </div>

   <div id="modal-form_yundan" class="modal fade" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-12 b-r">
                        <h3 class="m-t-none m-b">添加库存：</h3>
                        <form role="form" action="{:url('index/stock/fabricAddnum')}" method="post">
                            <div class="form-group">
                                <input type="name" placeholder="请填入数量" class="form-control" id="reaon" name="num">
                                <input type="hidden" id="orderid_yun" name="code" value="">
                            </div>
                            <div>
                                <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit"><strong>提交</strong>
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<!-- Peity -->
<script src="__INDEX__/js/plugins/peity/jquery.peity.min.js"></script>

<!-- 自定义js -->
<script src="__INDEX__/js/content.js?v=1.0.0"></script>


<!-- iCheck -->
<script src="__INDEX__/js/plugins/iCheck/icheck.min.js"></script>

<script>
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
    });
    function getInfo(id)
    {
        $('#orderid_yun').val(id);
    }
    /*导出excel*/
    function export_data()
    {
        var attr = '';
        $.each($('input:checkbox'),function(){
            if(this.checked){
                attr += $(this).val()+',';
            }
        });
        attr=attr.substring(0,attr.length-1);
        if(attr.length<1)/*说明没有选择数据*/
        {
            swal({   
                title: "没有导出数据",   
                text: "",   
                type: "error",  
            });
        }else{
            window.location.href = '/index/clothes/excel/attr/'+attr;
           // alert(123);
        }
    }
</script>
<script>
        function updateStatus(id,value)
        {
            swal({   
                title: "确定要修改状态吗?",   
                text: "确认将修改本条数据的状态!",   
                type: "warning",   
                showCancelButton: true,    
                confirmButtonText: "确认", 
                cancelButtonText: '取消',
                closeOnConfirm: false
            },function(){
                $.post('{:url("index/stock/updateStatus")}', {id: id,value:value}, function(data) {
                    if(data == 1){
                     swal({
                        title: "修改成功",
                        text: "",
                        type: "success"
                    });
                     window.location.reload(); 
                 }else{
                   swal({
                    title: "修改失败",
                    text: "",
                    type: "error"
                });
               }
           });
            });
        }
</script>
<script>
        function delcode(id)
        {
          swal({   
            title: "确定要删除数据?",   
            text: "确认将删除该条数据!",   
            type: "warning",   
            showCancelButton: true,    
            confirmButtonText: "确认", 
            cancelButtonText: '取消',
            closeOnConfirm: false
        }, function(){   
          $.post('{:url("index/stock/delfabric")}', {'id':id}, function(data) {
            if(data.sta == -1 ){
                swal({
                    title: "权限不足",
                    text: "",
                    type: "error"
                });
            }else if(data.sta == 1){
               swal({
                title: "删除成功",
                text: "",
                type: "success"
            });
               window.location.reload();
           }else{
            swal({
                title: "删除失败",
                text: "",
                type: "error"
            });                
        }
    });
      });
      }
</script>

<!-- 列表图片放大 -->
<script>
  function move(obj,json,fn){
　　clearInterval(obj.timer);
　 obj.timer=setInterval(function() {
  　　　　var onoff=true; 
  　　　　for(var attr in json){
  　　　　　　var icur=0;
  　　　　　　if(attr=='opacity'){
  　　　　　　　　icur=Math.round(parseFloat(getStyle(obj,attr))*100);
  　　　　　　}else{
  　　　　　　　　icur=parseInt(getStyle(obj,attr));
      　  }
  　　　　　　var speed=(json[attr]-icur)/10;
  　　　　　　speed=speed>0?Math.ceil(speed):Math.floor(speed);
  　　　　　　//检测是否停止
  　　　　　　if(icur !=json[attr]){             
  　　　　　　　　onoff=false;               
  　　　　　　}
  　　　　　　if(attr=='opacity'){
  　　　　　　　　//IE
  　　　　　　　　obj.style.filter="alpha(opacity='+icur+speed+')";    
  　　　　　　　　//firefox
  　　　　　　　　obj.style.opacity=(icur+speed)/100;
  　　　　　　}else{
  　　　　　　　　obj.style[attr]= icur+speed+'px';  
  　　　　　　}
  　　　　}
  　　　　if(onoff){              
  　　　　　　clearInterval(obj.timer);
  　　　　　　if(fn){
  　　　　　　　　fn(); 
       } 
  　　　　}
  　　},10);
  }

function getStyle(obj,attr){
　　//currentStyle针对IE浏览器 getComputedStyle针对火狐浏览器
　　if(obj.currentStyle){
    return currentStyle[attr];
　　}else{
    return  getComputedStyle(obj,false)[attr];
　　}
}

window.onload = function(){
    var aLi = $(".imgBig");
    var iMinZindex = 2;
    for(var i=0;i<aLi.length;i++){
        aLi[i].style.left = aLi[i].offsetLeft+'px';
        aLi[i].style.top = aLi[i].offsetTop+'px';
    }  
    for(var i=0;i<aLi.length;i++){
        aLi[i].style.position = 'absolute';
        aLi[i].style.margin = '0'; 
    }
    //缩放
    for(var i=0;i<aLi.length;i++){
        aLi[i].onmouseover = function(){
            this.style.zIndex = iMinZindex++;
            move(this,{width:300,height:200,marginLeft:-40,marginTop:-30});   //(200-120)/2=40
        }
        aLi[i].onmouseout = function(){
            move(this,{width:50,height:50,marginLeft:0,marginTop:0});
        }
    }
}
</script>

{/block}